package com.zyt.controller;

import com.zyt.pojo.PageResult;
import com.zyt.pojo.Result;
import com.zyt.pojo.Student;
import com.zyt.pojo.StudentQueryParam;
import com.zyt.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;
    /*
    *分页查询
     */
    @GetMapping
    public Result page(StudentQueryParam  studentQueryParam) {
         log.info("分页查询:{}", studentQueryParam);
        PageResult<Student> pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }
    /*
    *删除学员
     */
    @DeleteMapping("/{ids}")
    public Result delete( @PathVariable List<Integer> ids){
        log.info("删除员工:{}",ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }
    /*
    *增加学员
     */
     @PostMapping
    public Result save(@RequestBody Student student){
         log.info("保存员工:{}",student);
         studentService.save(student);
         return Result.success();
     }
     /*
     *修改学员
     */
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改员工:{}",student);
        studentService.update(student);
        return Result.success();
    }
    /*
    *根据id查询学员
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据id查询员工:{}",id);
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }
    /*
    *违纪处理
     */
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id,@PathVariable Integer score){
        log.info("违纪处理:{},{}",id,score);
        studentService.violation(id,score);
        return Result.success();
    }

}
